﻿using ERPPublic;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PersonnelManagement.Application.Command.PostCommand;
using PersonnelManagement.Domain.Dto;
using PersonnelManagement.Domain.PersonnelDomain;

namespace PersonnelManagement.Controllers
{
    /// <summary>
    /// 部门/岗位
    /// </summary>
    [Route("api/[controller]/[action]")]
    [Authorize]
    [ApiController]
    public class PostController : ControllerBase
    {

        protected readonly IMediator mediatorp;

        public PostController(IMediator mediatorp)
        {
            this.mediatorp = mediatorp;
        }

        /// <summary>
        /// 部门
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<SectorDto>>> GetSectorList([FromQuery] SectorListCommand command)
        {
            ApiResult<List<SectorDto>> result = new ApiResult<List<SectorDto>>();
            try
            {
                result.Data = await mediatorp.Send(command);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }


        /// <summary>
        /// 部门下的岗位
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<Post>>> GetPostList([FromQuery] PostListCommand command)
        {
            ApiResult<List<Post>> result = new ApiResult<List<Post>>();
            try
            {
                result.Data = await mediatorp.Send(command);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }


    }
}
